package com.aaa.base.controller;


import com.aaa.base.service.SupplierService;
import com.aaa.entity.base.Supplier;
import com.aaa.vo.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author aaa
 * @since 2020-11-23
 */
@RestController
@RequestMapping("/base/supplier")
public class SupplierController {
    @Autowired
    private SupplierService supplierService;

    @PostMapping("/searchSupplier/{page}/{limit}")
    @ApiOperation(value = "根据条件分页查询供应商")
    public R searchDept(@ApiParam(value = "当前页数") @PathVariable Integer page,
                                     @ApiParam(value = "每页个数") @PathVariable Integer limit,
                                     @ApiParam(value = "查询条件") @RequestBody Supplier supplier){
        Page<Supplier> supplierPage = supplierService.searchSupplier(page, limit, supplier);
        return R.ok().message("分页查询成功").code(200).data("page",supplierPage);
    }

    @PostMapping("/saveOrUpSupplier")
    @ApiOperation(value = "修改供应商方法")
    public R updSupplier(@RequestBody Supplier supplier){
        boolean b = supplierService.saveOrUpdate(supplier);
        if (b) {
            return R.ok().message("操作成功").code(200);
        }else {
            return R.error().message("操作失败").code(500);
        }
    }

    @PostMapping("/delSupplier/{id}")
    @ApiOperation(value = "删除供应商方法")
    public R delSupplier(@PathVariable Long id){
        boolean b = supplierService.removeById(id);
        if (b) {
            return R.ok().message("删除供应商成功").code(200);
        }else {
            return R.error().message("删除供应商失败").code(500);
        }
    }



}

